using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.Web.Security;

namespace Tests.sbMembership
{
    [SetUpFixture]
    public class TestSetup
    {
        public const string testUserName = "testuser";
        public const string testRoleName = "testrole";
        public const string testAddUserName = "testadduser";
        public const string testAddRoleName = "testaddrole";
        public const string testDeleteUserName = "testdeleteuser";
        public const string testDeleteRoleName = "testdeleterole";
        public const string testEditUserName = "testedituser";
        public const string testEditRoleName = "testeditrole";

        [SetUp]
        public void RunBeforeAnyTests()
        {
            // Create some test data for assigning roles to users
            Membership.CreateUser(testUserName, "password", testUserName + "@example.com");
            Membership.CreateUser(testDeleteUserName, "password", testDeleteUserName + "@example.com");
            Membership.CreateUser(testEditUserName, "password", testEditUserName + "@example.com");
            Roles.CreateRole(testRoleName);
            Roles.CreateRole(testDeleteRoleName);
            Roles.CreateRole(testEditRoleName);
        }

        [TearDown]
        public void RunAfterAnyTests()
        {
            // Delete everything that has been created during testing
            if (Membership.FindUsersByName(testUserName).Count > 0)
                Membership.DeleteUser(testUserName, true);
            if (Membership.FindUsersByName(testAddUserName).Count > 0)
                Membership.DeleteUser(testAddUserName, true);
            if (Membership.FindUsersByName(testDeleteUserName).Count > 0)
                Membership.DeleteUser(testDeleteUserName, true);
            if (Membership.FindUsersByName(testEditUserName).Count > 0)
                Membership.DeleteUser(testEditUserName, true);
            if (Roles.RoleExists(testRoleName))
                Roles.DeleteRole(testRoleName, false);
            if (Roles.RoleExists(testAddRoleName))
                Roles.DeleteRole(testAddRoleName, false);
            if (Roles.RoleExists(testDeleteRoleName))
                Roles.DeleteRole(testDeleteRoleName, false);
            if (Roles.RoleExists(testEditRoleName))
                Roles.DeleteRole(testEditRoleName, false);
        }
    }
}
